<?php

$uid = $_COOKIE["id"];

if (!empty($uid)) {
    
    //TODO Gerar resposta como um XML. Fica mais bonito[3] =D
    require_once("config.php");

    $con = @mysql_connect($mysql["host"] . ":" . $mysql["port"], $mysql["user"], $mysql["pass"]);

    if (!$con) {

        exit("1");
    }

    if (!@mysql_set_charset("utf8", $con)) {

        exit("1");
    }

    if (!@mysql_select_db($mysql["database"])) {

        exit("1");
    }
    
    $query = "SELECT * FROM `queries` WHERE `uid` = '$uid';";
    if ($rq = @mysql_query($query)) {

        header("Content-Type: text/xml");
        echo '<?xml version="1.0" encoding="utf-8"?>';
        echo '<Queries status="0">';
        while ($res = @mysql_fetch_array($rq)) {
            
            echo "<Querie qid='" . $res["id"] . "'>" . $res["query"] ."</Querie>";
        }
        echo '</Queries>';
    } else {
        
        exit("6");
    }
} else {
    
    exit("2");
}
?>
